package com.bz.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bz.common.PageInfo;
import com.bz.common.UserConfig;
import com.bz.dao.ServiceDao;
import com.bz.entity.ServiceEntity;
import com.bz.entity.UserEntity;
import com.bz.service.IServiceService;

@Service
public class ServiceServiceImpl implements IServiceService {

    @Autowired
    private ServiceDao serviceDao;

    @Override
    public PageInfo<ServiceEntity> list(PageInfo page, LambdaQueryWrapper<ServiceEntity> queryWrapper) {
        queryWrapper.orderByDesc(ServiceEntity::getUpdateDate);
        return serviceDao.selectPage(page, queryWrapper);
    }

    @Override
    public void add(ServiceEntity data) {
        UserEntity lu = UserConfig.getLoginUser();
        data.setCreateBy(lu.getUsername());
        data.setCreateDate(new Date());
        data.setUpdateBy(lu.getUsername());
        serviceDao.insert(data);
    }

    @Override
    public void update(ServiceEntity data) {
        UserEntity lu = UserConfig.getLoginUser();
        data.setUpdateBy(lu.getUsername());
        serviceDao.updateById(data);
    }

    @Override
    public void delete(Long id) {
        serviceDao.deleteById(id);
    }

}
